package com.xudow.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xudow.app.R;
import com.xudow.app.data.Pair;

import java.util.List;

/**
 * 课程区域Adapter
 *
 * @author lukecheng
 */
public class CourseLocationAdapter extends ArrayAdapter<Pair> {

    private LayoutInflater inflater;

    public CourseLocationAdapter(Context context, int resource, List<Pair> objects) {
        super(context, resource, objects);

        inflater = LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (null == convertView) {
            convertView = inflater.inflate(R.layout.layout_course_area, null);

            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.name);
            holder.icon = (ImageView) convertView.findViewById(R.id.icon);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Pair item = getItem(position);
        holder.name.setText(item.first);

        if (item.checked) {
            holder.icon.setVisibility(View.VISIBLE);
        } else {
            holder.icon.setVisibility(View.GONE);
        }

        return convertView;
    }

    private class ViewHolder {
        public TextView name;
        private ImageView icon;
    }
}
